<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_faceid/model')->方法名();
*/
namespace jy_faceid;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function addlog($postdata=array()){
		$log=$this->pdo_get('log',array('mid'=>$_SESSION['uid'],'passed'=>0));
		$data=array(
			'sn'=>'SN'.get_ordersn($this->tablename('log'),'sn'),
			'realname'=>$postdata['realname'],
			'cardnum'=>$postdata['cardnum'],
			'cardimg1'=>$postdata['cardimg1'],
			'cardimg2'=>$postdata['cardimg2'],
			'orderid'=>$postdata['orderid'],
			'type'=>$postdata['type'],
			'response_data'=>$postdata['response_data'],
			'passed'=>$postdata['passed']?:0,
		);
		if($postdata['passed']){
			$cardinfo=array(
				'realname'=>$postdata['realname'],
				'cardnum'=>$postdata['cardnum'],
				'cardimg1'=>$postdata['cardimg1'],
				'cardimg2'=>$postdata['cardimg2'],
			);
			$update=array('isrealname'=>1,'realname'=>$postdata['realname'],'cardnum'=>$postdata['cardnum'],'cardinfo'=>ijson_encode($cardinfo));
			if($postdata['mobile']){
				$update['mobile']=$postdata['mobile'];
			}
			pdo_update('core_members',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']));
		}
		if($data['orderid']){
			$ordersn=pdo_getcolumn('jy_weishop_order',array('id'=>$data['orderid']),'ordersn');
			$data['ordersn']=$ordersn;
		}
		if($log['id']){
			$this->pdo_update('log',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$log['id']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			$data['createtime']=TIMESTAMP;
			$this->pdo_insert('log',$data);
		}
		return false;
	}
}
?>